package com.yidu.service.impl;

import java.util.List;
import java.util.UUID;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.yidu.dao.LockerUserMapper;
import com.yidu.model.LockerUser;
import com.yidu.service.UserService;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author roots
 * @since 2018-10-20
 */
@Service
public class UserServiceImpl implements UserService {

	@Resource
	private LockerUserMapper mapper;
	
	@Override
	public List<LockerUser> findAll(LockerUser user) {
		return mapper.selectAll(user);
	}
	/**
	 * 删除
	 */
	@Override
	public int delete(String userId) {
		return mapper.deleteByPrimaryKey(userId);
	}
	/**
	 * 增加或者修改
	 */
	@Override
	public int addOrUpdate(LockerUser user) {
		System.out.println("================================="+user.getUserId());
		if(user.getUserId()!=null && !"".equals(user.getUserId())) {
			return mapper.updateByPrimaryKey(user);
		}else {
			String uuid = UUID.randomUUID().toString().replaceAll("-", "");
			user.setUserId(uuid);
			return mapper.insert(user);
		}
	}
	/**
	 * 根据id查询   赋值修改
	 */
	@Override
	public LockerUser findById(String userId) {
		LockerUser user = mapper.selectByPrimaryKey(userId);
		return user;
	}
	/**
	 * 根据姓名查询
	 */
	@Override
	public List<LockerUser> findName(LockerUser user) {
		return mapper.findName(user);
	}
	/**
	 * 增加
	 */
	@Override
	public void add(LockerUser user) {
		mapper.insert(user);
	}
	/**
	 * 查询用户名密码是否正确
	 */
	@Override
	public LockerUser queryNameOrPwd(LockerUser user) {
		System.out.println(user.getUserName());
		return mapper.queryNameOrPwd(user);
	}
	@Override
	public int upjin(LockerUser user) {
		return mapper.upjin(user);
	}
}
